package net.begincode.admin.controller;

import net.begincode.admin.bean.HomeTypeEditParam;
import net.begincode.admin.bean.HomeTypeParam;
import net.begincode.biz.HomeTypeBiz;
import net.begincode.blog.entity.HomeType;
import net.begincode.blog.enums.HomeTypeFlagEnum;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import javax.annotation.Resource;
import java.util.Date;

/**
 * 网站栏目分类
 * */
@Controller
@RequestMapping("/admin/homeType/")
public class HomeTypeController {
    @Resource
    private HomeTypeBiz homeTypeBiz;
    /**
     * 新增网站分类
     * */
    @RequestMapping("add")
    public ModelAndView add(HomeTypeParam homeTypeParam) {
        homeTypeParam.checkParam();
        HomeType homeType = new HomeType();
        homeType.setCdate(new Date());
        homeType.setFlag(HomeTypeFlagEnum.EFFECT.getFlagCode());
        homeType.setPriority(homeTypeParam.getPriority());
        homeType.setTypeName(homeTypeParam.getTypeName());
        homeTypeBiz.addHomeType(homeType);
        ModelAndView modelAndView = new ModelAndView();
        modelAndView.setViewName("homeTypeList");
        return modelAndView;
    }
    /**
     * 更新网站分类
     * */
    @RequestMapping("update")
    public ModelAndView update(HomeTypeEditParam homeTypeEditParam) {
        homeTypeEditParam.checkParam();
        HomeType homeType = new HomeType();
        homeType.setCdate(new Date());
        homeType.setPriority(homeTypeEditParam.getPriority());
        homeType.setTypeName(homeTypeEditParam.getTypeName());
        homeType.setId(homeTypeEditParam.getId());
        homeTypeBiz.updateHomeTypeById(homeType);
        ModelAndView modelAndView = new ModelAndView();
        modelAndView.setViewName("homeTypeList");
        return modelAndView;
    }
}
